home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / c / MEMLib.lha / MEMLib / Developer / source / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-30  |  1.1 KB  |  47 lines

  1. #include "main.h"
  2.  
  3. int main(int ac, char *av)
  4. {
  5.     char *a;
  6.     void *b;
  7.     char n[]="This is a sample text";
  8.  
  9.     a = AllocMem(20, 0);  /* Note that we never free this memory */
  10.  
  11.     a = AllocMem(10, 0);
  12.  
  13.     FreeMem(a, 9);  /* Note that we free an incorrect length here */
  14.  
  15.     a = AllocVec(10, 0);
  16.  
  17.     free(a);  /* Freed with wrong free routine */
  18.  
  19.     a = strdup("test"); /* Note that we never free this memory */
  20.  
  21.     a = getcwd(NULL, 1000);
  22.     free(a);
  23.     free(a);  /* Note that we're freeing the memory twice! */
  24.  
  25.  
  26.     /* now use standard malloc and free functions */
  27.     b = (void *)malloc(10);
  28.     free(b);
  29.  
  30.     /* now, how about assigning in a an if-statement */
  31.     if ((b = (void *)malloc(strlen(n)+1)) == NULL)
  32.         b = (void *)0xdeadbeef;
  33.  
  34.     free(b);
  35.  
  36.     putenv("MWTest=xx");
  37.     a = getenv("MWTest");
  38.     if(a) a[strlen(a)+1] = 0;  /* Note we're trashing a byte!!!      */
  39.                                /* This shouldn't cause a real crash  */
  40.                                /* since malloc() allocates in clumps */
  41.                                /* of 4 bytes, and 'a' is 3 bytes.    */
  42.  
  43.     MWReport("At end of main()", MWR_FULL);  /* Generate a memory usage report */
  44.  
  45.     return(0);
  46. }
  47.